/*
 * Cerval.java
 *
 * Created on 1 de Outubro de 2008, 02:36
 */
package manager.principal.fonte;

import java.io.IOException;
import java.sql.SQLException;
import java.util.LinkedList;
import javax.swing.*;
import manager.auxiliares.*;
import manager.modulo.clientefornecedor.fonte.RegistroCentroCusto;
import manager.modulo.estoque.fonte.RegistroEntradaEstoque;
import manager.modulo.estoque.fonte.RegistroInsumo;
import manager.modulo.ferramenta.fonte.RegistroFerramenta;
import manager.modulo.ferramenta.fonte.RegistroHistoricoFerramenta;
import manager.modulo.financeiro.RegistroCategoriaFinanceira;
import manager.modulo.financeiro.RegistroEntradaFinanceira;
import manager.modulo.funcionario.fonte.RegistroFuncionario;
import manager.modulo.ordemservico.fonte.PainelAvaliacao;
import manager.modulo.ordemservico.fonte.RegistroOrdemServico;
import manager.modulo.ordemservico.fonte.RegistroPontoAtendimento;
import manager.modulo.ordemservico.fonte.RegistroProcedimento;
import manager.modulo.clientefornecedor.fonte.RegistroClienteFornecedor;
import manager.modulo.estoque.fonte.RegistroComposicao;
import manager.modulo.estoque.fonte.RegistroSaídaEstoque;
import manager.modulo.orcamento.fonte.RegistroOrcamento;
import manager.modulo.sistema.fonte.RegistroUsuario;
import manager.modulo.sistema.dao.ModuleDao;

/**
 *
 * @author diego1
 */
public class JanelaPrincipal extends javax.swing.JFrame {

    //Módulo de Sistema
    PainelRegistro janelaSistema;
    //Módulo de CLiente/Fornecedor
    PainelRegistro janelaClienteFornecedor;
    PainelRegistro janelaCentroCusto;
    //Ordem de Serviço
    PainelRegistro registroOrdemServico;
    PainelRegistro registroProcedimento;
    PainelRegistro registroPontoAtendimento;
    PainelAvaliacao painelAvaliacaoOS;
    //Funcionário
    PainelRegistro registroFuncionario;
    //Módulo de Ferramentas
    PainelRegistro registroFerramenta;
    PainelRegistro registroHistoricoFerramenta;
    //Módulo de Estoque
    PainelRegistro registroInsumos;
    PainelRegistro registroComposicao;
    PainelRegistro registroEntradaEstoque;
    PainelRegistro registroSaidaEstoque;
    //Módulo Orçamento
    PainelRegistro registroOrcamento;
    //Financeiro
    PainelRegistro registroCategoriaFinanceira;
    PainelRegistro registroFinanceiro;
    LinkedList<ModuleMenu> menuList;
    ModuleMenu moduleMenuSelected;
    JPanel currentSelectedItem;
    int menuPosition = 0;

    /**
     * Creates new form Cerval
     */
    public JanelaPrincipal() throws SQLException {
        try {
            // Define layout de acordo com o SO que estiver rodando
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        this.setIconImage(JanelaLogin.icon);
        initComponents();
        adicionarIconesTabledPaneAgricola();
        connectionStatus();
        configureMenu();
        // criarMenuVersao();
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        this.setVisible(true);
    }

    /**
     * Configura os menus do sistema
     */
    private void configureMenu() {
        try {
            LinkedList<String> moduleList = ModuleDao.systemModules();
            LinkedList<String> moduleUser = ModuleDao.modulesByIdUser(JanelaLogin.getUsuario().getId());
            menuList = new LinkedList<ModuleMenu>();

            for (int i = 0; i < moduleList.size(); i++) {
                String menu = moduleList.get(i);
                if (moduleUser.contains(menu)) {
                    LinkedList subMenu = new LinkedList();
                    ModuleMenu moduleMenu = null;
                    //Menu de sistema
                    if (menu.equalsIgnoreCase("Sistema")) {
                        subMenu.add("Usuários");
                        moduleMenu = new ModuleMenu(subMenu, menu, new Icons().getSystemModule());
                    } else if (menu.equalsIgnoreCase("Cliente/Fornecedor")) {
                        subMenu.add("Cliente/Fornecedor");
                        subMenu.add("Centro de Custo");
                        moduleMenu = new ModuleMenu(subMenu, menu, new Icons().getPartnerModule());
                    } else if (menu.equalsIgnoreCase("Financeiro")) {
                        subMenu.add("Lançamentos");
                        subMenu.add("Categorias");
                        moduleMenu = new ModuleMenu(subMenu, menu, new Icons().getFinancialModule());
                    } else if (menu.equalsIgnoreCase("Ordem de Serviço")) {
                        subMenu.add("Gereciamento de OS");
                        subMenu.add("Procedimento");
                        subMenu.add("Ponto de Atendimento");
                        subMenu.add("Avaliação OS");
                        moduleMenu = new ModuleMenu(subMenu, menu, new Icons().getModuloOrdemServico());
                    } else if (menu.equalsIgnoreCase("Funcionário")) {
                        subMenu.add("Funcionários");
                        moduleMenu = new ModuleMenu(subMenu, menu, new Icons().getModuloFuncionario());
                    } else if (menu.equalsIgnoreCase("Ferramentas")) {
                        subMenu.add("Ferramentas");
                        subMenu.add("Histórico de Ferramentas");
                        moduleMenu = new ModuleMenu(subMenu, menu, new Icons().getModuloFerramenta());
                    } else if (menu.equalsIgnoreCase("Estoque")) {
                        subMenu.add("Insumos");
                        subMenu.add("Composições");
                        subMenu.add("Entrada de Estoque");
                        subMenu.add("Saída de Estoque");
                        moduleMenu = new ModuleMenu(subMenu, menu, new Icons().getModuloEstoque());
                    } else if (menu.equalsIgnoreCase("Orçamento")) {
                        subMenu.add("Orçamento");
                        moduleMenu = new ModuleMenu(subMenu, menu, new Icons().getModuloOrcamento());
                    }
                    menuList.add(moduleMenu);

                }
            }
            addMenuFunctions();
        } catch (Exception e) {
            MensagemExcessao.mostrarMensagem(e, "Configurando Menu do Sistema");
        }
    }

    /**
     * Adicionar as funcionalidades dos menus
     */
    private void addMenuFunctions() {
        for (int i = 0; i < menuList.size(); i++) {
            if (menuList.get(i) != null) {
                ModuleMenu moduleMenu = (ModuleMenu) menuList.get(i);

                jPanel4.add(moduleMenu.getjPanelMenu());
                moduleMenu.getjPanelMenu().setBounds(0, i * 35, 196, 35);

                jPanel4.add(moduleMenu.getjPanelSubMenu());
                moduleMenu.getjPanelSubMenu().setBounds(7, moduleMenu.getjPanelMenu().getY() + moduleMenu.getjPanelMenu().getHeight(), 182, moduleMenu.getSubMenuList().size() * 18);
                moduleMenu.getjPanelSubMenu().setVisible(false);

                moduleMenu.getjPanelMenu().addMouseListener(new java.awt.event.MouseAdapter() {
                    @Override
                    public void mouseReleased(java.awt.event.MouseEvent evt) {
                        for (int j = 0; j < menuList.size(); j++) {
                            ModuleMenu moduleMenu = (ModuleMenu) menuList.get(j);
                            if (evt.getComponent() == moduleMenu.getjPanelMenu()) {
                                selectModuleMenu(moduleMenu);
                            }
                        }
                    }
                });
                for (int j = 0; j < moduleMenu.getjPanelSubMenuItens().size(); j++) {
                    JPanel jPanelMenuItem = moduleMenu.getjPanelSubMenuItens().get(j);
                    jPanelMenuItem.addMouseListener(new java.awt.event.MouseAdapter() {
                        @Override
                        public void mouseReleased(java.awt.event.MouseEvent evt) {
                            ModuleMenu moduleMenu = getModuleMenuSelected();
                            int index = moduleMenu.getjPanelSubMenuItens().indexOf(evt.getComponent());
                            changeMenu(moduleMenu.getTitleModule(), moduleMenu.getSubMenuList().get(index));
                            if (currentSelectedItem != null) {
                                currentSelectedItem.setBorder(javax.swing.BorderFactory.createEtchedBorder());
                            }
                            currentSelectedItem = (JPanel) evt.getComponent();
                            currentSelectedItem.setBorder(javax.swing.BorderFactory.createEtchedBorder(Configurations.getjPanelSelectedColor(), Configurations.getjPanelSelectedColor()));
                        }
                    });
                }
            }
        }
    }

    /**
     * Selecioanr um modulo do sistema
     *
     * @param moduleMenu Módulo a ser selecionado
     */
    private void selectModuleMenu(ModuleMenu moduleMenu) {
        if (moduleMenuSelected != moduleMenu) {
            try {
                unselectModuleMenu(false);
                moduleMenuSelected = moduleMenu;
                moduleMenu.setSelected(true);
                moduleMenu.getjPanelMenu().setBackground(Configurations.getjPanelSelectedColor());
                moduleMenu.getjPanelSubMenu().setVisible(true);
                int index = menuList.indexOf(moduleMenuSelected);
                for (int i = index + 1; i < menuList.size(); i++) {
                    JPanel jPanelModule = menuList.get(i).getjPanelMenu();
                    ModuleMenu lastMenu = menuList.get(i - 1);
                    int menuY = lastMenu.getjPanelMenu().getY();
                    int menuHeigth = jPanelModule.getHeight();
                    if (lastMenu.getSelected()) {
                        menuY = lastMenu.getjPanelSubMenu().getY();
                        menuHeigth = lastMenu.getjPanelSubMenu().getHeight();
                    }
                    jPanelModule.setBounds(0, menuY + menuHeigth - 1, 196, 35);
                }
            } catch (Exception e) {
            }
        } else {
            unselectModuleMenu(true);
        }
    }

    /**
     * Remover a seleção dos módulos do sistem
     *
     * @param current Este parâmetro indica se o módulo a ser desselecionados é
     * o módulo selecionado atualmente.
     */
    private void unselectModuleMenu(boolean current) {
        if (moduleMenuSelected != null) {
            try {
                moduleMenuSelected.setSelected(false);
                moduleMenuSelected.getjPanelSubMenu().setVisible(false);
                if (!current) {
                    moduleMenuSelected.getjPanelMenu().setBackground(Configurations.getBackGroundColor());
                }
                int index = menuList.indexOf(moduleMenuSelected);
                for (int i = index + 1; i < menuList.size(); i++) {
                    JPanel jPanelModule = menuList.get(i).getjPanelMenu();
                    jPanelModule.setBounds(0, (menuList.get(i - 1).getjPanelMenu().getY() + 35), 196, 35);
                }
                moduleMenuSelected = null;
            } catch (Exception e) {
            }
        }
    }

    /**
     * Muda o conteúdo do painel principal do sistema
     *
     * @param newPanel Novo painel a ser adicionado
     */
    private void changeContent(JPanel newPanel) {
        jPanel9.removeAll();
        jPanel9.add(newPanel);
        jPanel9.repaint();
        jPanel9.revalidate();
    }

    /**
     * Seleciona algum menu do sistema e muda seu conteudo baseado na seleção
     *
     * @param menu Nome do menu a ser selecionado
     * @param subMenu Nome do subMenu
     */
    private void changeMenu(String menu, String subMenu) {
        if (menu.equalsIgnoreCase("Sistema")) {
            if (subMenu.equalsIgnoreCase("Usuários")) {
                if (janelaSistema == null) {
                    janelaSistema = new PainelRegistro(new RegistroUsuario());
                }
                changeContent(janelaSistema);
            }
        } else if (menu.equalsIgnoreCase("Cliente/Fornecedor")) {
            if (subMenu.equalsIgnoreCase("Cliente/Fornecedor")) {
                if (janelaClienteFornecedor == null) {
                    janelaClienteFornecedor = new PainelRegistro(new RegistroClienteFornecedor());
                }
                changeContent(janelaClienteFornecedor);
            } else if (subMenu.equalsIgnoreCase("Centro de Custo")) {
                if (janelaCentroCusto == null) {
                    janelaCentroCusto = new PainelRegistro(new RegistroCentroCusto());
                }
                changeContent(janelaCentroCusto);
            }
        } else if (menu.equalsIgnoreCase("Financeiro")) {
            if (subMenu.equalsIgnoreCase("Lançamentos")) {
                if (registroFinanceiro == null) {
                    registroFinanceiro = new PainelRegistro(new RegistroEntradaFinanceira());
                }
                changeContent(registroFinanceiro);
            } else if (subMenu.equalsIgnoreCase("Categorias")) {
                if (registroCategoriaFinanceira == null) {
                    registroCategoriaFinanceira = new PainelRegistro(new RegistroCategoriaFinanceira());
                }
                changeContent(registroCategoriaFinanceira);
            }
        } else if (menu.equalsIgnoreCase("Ordem de Serviço")) {
            if (subMenu.equalsIgnoreCase("Gereciamento de OS")) {
                if (registroOrdemServico == null) {
                    registroOrdemServico = new PainelRegistro(new RegistroOrdemServico());
                }
                changeContent(registroOrdemServico);
            } else if (subMenu.equalsIgnoreCase("Procedimento")) {
                if (registroProcedimento == null) {
                    registroProcedimento = new PainelRegistro(new RegistroProcedimento());
                }
                changeContent(registroProcedimento);
            } else if (subMenu.equalsIgnoreCase("Ponto de Atendimento")) {
                if (registroPontoAtendimento == null) {
                    registroPontoAtendimento = new PainelRegistro(new RegistroPontoAtendimento());
                }
                changeContent(registroPontoAtendimento);
            } else if (subMenu.equalsIgnoreCase("Avaliação OS")) {
                if (painelAvaliacaoOS == null) {
                    painelAvaliacaoOS = new PainelAvaliacao();
                }
                changeContent(painelAvaliacaoOS);
            }
        } else if (menu.equalsIgnoreCase("Funcionário")) {
            if (subMenu.equalsIgnoreCase("Funcionários")) {
                if (registroFuncionario == null) {
                    registroFuncionario = new PainelRegistro(new RegistroFuncionario());
                }
                changeContent(registroFuncionario);
            }
        } else if (menu.equalsIgnoreCase("Ferramentas")) {
            if (subMenu.equalsIgnoreCase("Ferramentas")) {
                if (registroFerramenta == null) {
                    registroFerramenta = new PainelRegistro(new RegistroFerramenta());
                }
                changeContent(registroFerramenta);
            } else if (subMenu.equalsIgnoreCase("Histórico de Ferramentas")) {
                if (registroHistoricoFerramenta == null) {
                    registroHistoricoFerramenta = new PainelRegistro(new RegistroHistoricoFerramenta());
                }
                changeContent(registroHistoricoFerramenta);
            }
        } else if (menu.equalsIgnoreCase("Estoque")) {
            if (subMenu.equalsIgnoreCase("Insumos")) {
                if (registroInsumos == null) {
                    registroInsumos = new PainelRegistro(new RegistroInsumo());
                }
                changeContent(registroInsumos);
            } else if (subMenu.equalsIgnoreCase("Composições")) {
                if (registroComposicao == null) {
                    registroComposicao = new PainelRegistro(new RegistroComposicao());
                }
                changeContent(registroComposicao);
            } else if (subMenu.equalsIgnoreCase("Entrada de Estoque")) {
                if (registroEntradaEstoque == null) {
                    registroEntradaEstoque = new PainelRegistro(new RegistroEntradaEstoque());
                }
                changeContent(registroEntradaEstoque);
            } else if (subMenu.equalsIgnoreCase("Saída de Estoque")) {
                if (registroSaidaEstoque == null) {
                    registroSaidaEstoque = new PainelRegistro(new RegistroSaídaEstoque());
                }
                changeContent(registroSaidaEstoque);
            }
        } else if (menu.equalsIgnoreCase("Orçamento")) {
            if (subMenu.equalsIgnoreCase("Orçamento")) {
                if (registroOrcamento == null) {
                    registroOrcamento = new PainelRegistro(new RegistroOrcamento());
                }
                changeContent(registroOrcamento);
            }
        }

    }

    /**
     * Retorna o módulo do menu que esta selecionado atualmente
     *
     * @return Módulo do menu que esta selecionado
     */
    private ModuleMenu getModuleMenuSelected() {
        return moduleMenuSelected;
    }

    /**
     * Seleciona algum módulo do menu para o atual
     *
     * @param moduleMenuSelected Módulo do menu a ser selecionado
     */
    private void setModuleMenuSelected(ModuleMenu moduleMenuSelected) {
        this.moduleMenuSelected = moduleMenuSelected;
    }

    /**
     * Sair do programa
     */
    public void exit() {
        Object[] options = {"Sim", "Não"};
        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        int j = JOptionPane.showOptionDialog(null, "Tem certeza que deseja sair?", "Sair", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        if (j == JOptionPane.YES_OPTION) {
            this.dispose();
            System.exit(0);
        }
    }

    /**
     * Thread para verificar o status do sistema em relação ao banco de dados.
     */
    private void connectionStatus() {
        try {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new ConnectionStatus(jLabel26, jLabel55, jLabel29);
                }
            });
        } catch (Exception e) {
            //  e.printStackTrace();
            System.err.println("ERRO interno de execução!");
        }
    }

    private void adicionarIconesTabledPaneAgricola() {
        jTabbedPane1.removeAll();
        jTabbedPane1.addTab("Sistema", new Icons().getConfigure(), jPanel20);
        jTabbedPane1.addTab("Calendário", new Icons().getCalendar(), jPanel21);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel28 = new javax.swing.JPanel();
        jPanel25 = new javax.swing.JPanel();
        jLabel33 = new javax.swing.JLabel();
        jPanel27 = new javax.swing.JPanel();
        jLabel35 = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jLabel38 = new javax.swing.JLabel();
        jPanel13 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel20 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jLabel55 = new javax.swing.JLabel();
        jPanel21 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel9 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem10 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem38 = new javax.swing.JMenuItem();
        jMenu8 = new javax.swing.JMenu();
        jMenuItem15 = new javax.swing.JMenuItem();
        jMenuItem37 = new javax.swing.JMenuItem();
        jMenu9 = new javax.swing.JMenu();
        jMenuItem20 = new javax.swing.JMenuItem();
        jMenuItem29 = new javax.swing.JMenuItem();
        jMenuItem34 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem14 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Taldi Engenharia");
        setMinimumSize(new java.awt.Dimension(1020, 550));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBackground(Configurations.getBackGroundColor());
        jPanel1.setPreferredSize(new java.awt.Dimension(850, 610));

        jPanel2.setBackground(Configurations.getBackGroundColor());

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setLayout(null);

        jPanel28.setLayout(new java.awt.GridLayout(2, 0));

        jPanel25.setBackground(new java.awt.Color(233, 233, 233));
        jPanel25.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel25.setLayout(new java.awt.GridBagLayout());

        jLabel33.setForeground(new java.awt.Color(51, 51, 255));
        jLabel33.setText("Cadastrar e Editar");
        jPanel25.add(jLabel33, new java.awt.GridBagConstraints());

        jPanel28.add(jPanel25);

        jPanel27.setBackground(new java.awt.Color(233, 233, 233));
        jPanel27.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jPanel27.setLayout(new java.awt.GridBagLayout());

        jLabel35.setForeground(new java.awt.Color(51, 51, 255));
        jLabel35.setText("Histórico de Faturas");
        jPanel27.add(jLabel35, new java.awt.GridBagConstraints());

        jPanel28.add(jPanel27);

        jPanel4.add(jPanel28);
        jPanel28.setBounds(230, 80, 182, 36);

        jLabel37.setText("Financeiro");
        jPanel4.add(jLabel37);
        jLabel37.setBounds(300, 60, 50, 14);
        jPanel4.add(jLabel38);
        jLabel38.setBounds(290, 150, 110, 0);

        jPanel13.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel13.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jPanel13.setLayout(null);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Sistema");
        jPanel13.add(jLabel6);
        jLabel6.setBounds(45, 5, 100, 14);

        jLabel16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/configure.png"))); // NOI18N
        jPanel13.add(jLabel16);
        jLabel16.setBounds(2, 2, 20, 20);

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/Down.gif"))); // NOI18N
        jPanel13.add(jLabel11);
        jLabel11.setBounds(164, 5, 20, 15);

        jPanel4.add(jPanel13);
        jPanel13.setBounds(220, 30, 192, 25);

        //calendario.setBounds(0, 0, 100, 100);
        jPanel5.setBackground(Configurations.getBackGroundColor());
        jPanel5.setLayout(new java.awt.GridLayout(1, 0));

        jTabbedPane1.setBackground(Configurations.getBackGroundColor());

        jPanel20.setBackground(new java.awt.Color(255, 255, 255));
        jPanel20.setBorder(BorderFactory.createEtchedBorder());
        jPanel20.setLayout(null);

        jLabel22.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel22.setText("Versão "+manager.principal.fonte.JanelaLogin.getVersion());
        jPanel20.add(jLabel22);
        jLabel22.setBounds(10, 10, 170, 15);

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel23.setText("Usuário : ");
        jPanel20.add(jLabel23);
        jLabel23.setBounds(10, 30, 60, 14);

        jLabel24.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        jLabel24.setText("Usuário do Programa Taldi");
        jLabel24.setText(manager.principal.fonte.JanelaLogin.getUsuario().getEmail());
        jPanel20.add(jLabel24);
        jLabel24.setBounds(10, 50, 170, 14);

        jLabel25.setFont(new java.awt.Font("Tahoma", 2, 15)); // NOI18N
        jLabel25.setText("25/03/1988");
        jLabel25.setText(DateConverter.getCurrentDateInterface());
        jPanel20.add(jLabel25);
        jLabel25.setBounds(10, 88, 90, 20);

        jLabel26.setFont(new java.awt.Font("Tahoma", 2, 15)); // NOI18N
        jLabel26.setText("16:20:20");
        jPanel20.add(jLabel26);
        jLabel26.setBounds(115, 88, 60, 20);

        jLabel27.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel27.setText("Data :");
        jPanel20.add(jLabel27);
        jLabel27.setBounds(10, 70, 33, 14);

        jLabel28.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel28.setText("Hora :");
        jPanel20.add(jLabel28);
        jLabel28.setBounds(115, 70, 40, 14);

        jLabel29.setFont(new java.awt.Font("Times New Roman", 1, 15)); // NOI18N
        jLabel29.setForeground(new java.awt.Color(204, 0, 51));
        jLabel29.setText("Desconectado");
        jPanel20.add(jLabel29);
        jLabel29.setBounds(50, 110, 100, 19);

        jLabel55.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/desconected.png"))); // NOI18N
        jPanel20.add(jLabel55);
        jLabel55.setBounds(20, 110, 20, 20);

        jTabbedPane1.addTab("Sistema", jPanel20);

        jPanel21.setBackground(Configurations.getBackGroundColor());
        jPanel21.setLayout(new java.awt.GridLayout(1, 0));
        Dialog_Calendar calendar = new Dialog_Calendar();
        jPanel21.add(calendar);
        jTabbedPane1.addTab("Calendário", jPanel21);

        jPanel5.add(jTabbedPane1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel3.setLayout(new java.awt.GridLayout(1, 0));

        jPanel9.setBackground(new java.awt.Color(255, 255, 255));
        jPanel9.setLayout(new java.awt.GridLayout());

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/taldi.png"))); // NOI18N
        jPanel9.add(jLabel5);

        jScrollPane1.setViewportView(jPanel9);

        jPanel3.add(jScrollPane1);
        jScrollPane1.getVerticalScrollBar().setUnitIncrement(30);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 970, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 604, Short.MAX_VALUE))
                .addContainerGap())
        );

        jMenu1.setText("Opções");

        jMenuItem10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/logout.png"))); // NOI18N
        jMenuItem10.setText("Logout");
        jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem10ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem10);

        jMenuItem6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/close.png"))); // NOI18N
        jMenuItem6.setText("Sair");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem6);

        jMenuBar1.add(jMenu1);

        jMenu3.setText("Exibir");
        jMenu3.setEnabled(false);
        jMenuBar1.add(jMenu3);

        jMenu5.setText("Ferramentas");

        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/calculator.png"))); // NOI18N
        jMenuItem4.setText("Calculadora");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem4);

        jMenuItem38.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/zoomin.png"))); // NOI18N
        jMenuItem38.setText("Analisador de Faturas");
        jMenuItem38.setEnabled(false);
        jMenuItem38.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem38ActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuItem38);

        jMenu8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/save.png"))); // NOI18N
        jMenu8.setText("Backup / Restore");
        jMenu8.setEnabled(false);

        jMenuItem15.setText("Realizar Backup");
        jMenuItem15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem15ActionPerformed(evt);
            }
        });
        jMenu8.add(jMenuItem15);

        jMenuItem37.setText("Restaurar o Sistema");
        jMenuItem37.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem37ActionPerformed(evt);
            }
        });
        jMenu8.add(jMenuItem37);

        jMenu5.add(jMenu8);

        jMenuBar1.add(jMenu5);

        jMenu9.setText("Alertas");
        jMenu9.setEnabled(false);

        jMenuItem20.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/alert.png"))); // NOI18N
        jMenuItem20.setText("Histórico de Faturas");
        jMenuItem20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem20ActionPerformed(evt);
            }
        });
        jMenu9.add(jMenuItem20);

        jMenuItem29.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/alert.png"))); // NOI18N
        jMenuItem29.setText("Estoque Mínimo");
        jMenuItem29.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem29ActionPerformed(evt);
            }
        });
        jMenu9.add(jMenuItem29);

        jMenuItem34.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/alert.png"))); // NOI18N
        jMenuItem34.setText("Trocas de Óleo");
        jMenuItem34.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem34ActionPerformed(evt);
            }
        });
        jMenu9.add(jMenuItem34);

        jMenuBar1.add(jMenu9);

        jMenu2.setText("Ajuda");

        jMenuItem9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/help.png"))); // NOI18N
        jMenuItem9.setText("Manual");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem9);

        jMenu4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/unlock.png"))); // NOI18N
        jMenu4.setText("Ativar");
        jMenu4.setEnabled(false);

        jMenuItem3.setText("jMenuItem3");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem3);

        jMenu2.add(jMenu4);

        jMenuItem14.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/icone_16x16.png"))); // NOI18N
        jMenuItem14.setText("Sobre");
        jMenuItem14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem14ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem14);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1168, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    exit();
}//GEN-LAST:event_formWindowClosing

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
}//GEN-LAST:event_jMenuItem3ActionPerformed

private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
    try {
        Runtime.getRuntime().exec("calc");
    } catch (IOException iOException) {
        MensagemExcessao.mostrarMensagem(iOException, "Calculadora");
    }
}//GEN-LAST:event_jMenuItem4ActionPerformed

private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
    this.dispose();
    new JanelaLogin();
}//GEN-LAST:event_jMenuItem10ActionPerformed

private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
    exit();
}//GEN-LAST:event_jMenuItem6ActionPerformed

private void jMenuItem14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem14ActionPerformed
    JanelaSobre sobre = new JanelaSobre(this, false);
    sobre.setLocationRelativeTo(null);
    sobre.setIconImage(this.getIconImage());
    sobre.setVisible(true);
}//GEN-LAST:event_jMenuItem14ActionPerformed

private void jMenuItem20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem20ActionPerformed
//    new VerificarAlarmes(this, 0, 1).start();
}//GEN-LAST:event_jMenuItem20ActionPerformed

private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
    JOptionPane.showMessageDialog(null, "O sistema de ajuda ainda não foi implementado. Entre em contato com o suporte através do menu sobre.", "Ajuda", JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_jMenuItem9ActionPerformed

private void jMenuItem29ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem29ActionPerformed
//    try {
//        if (panel_Estoque != null) {
//            Dialog_MensagemEstoque dialog_MensagemEstoque = new Dialog_MensagemEstoque(this, false);
//            dialog_MensagemEstoque.setLocationRelativeTo(null);
//            dialog_MensagemEstoque.setIconImage(new ImageIcons().getAlert());
//            dialog_MensagemEstoque.checarEstoque(panel_Estoque.getIdEstoqueSelecionado());
//        } else {
//            JOptionPane.showMessageDialog(null, "Inicialize o módulo de estoque e selecione um estoque para verificar o estoque mínimo.", "Estoque Mínimo", JOptionPane.INFORMATION_MESSAGE);
//        }
//    } catch (Exception e) {
//        MensagemException.showMensageException(e, "Estoque Mínimo");
//    }
}//GEN-LAST:event_jMenuItem29ActionPerformed

private void jMenuItem34ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem34ActionPerformed
//    new VerificarAlarmes(this, 1, 0).start();
}//GEN-LAST:event_jMenuItem34ActionPerformed

private void jMenuItem15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem15ActionPerformed
//    try {
//        Object[] options2 = {"Sim", "Não"};
//        int j = JOptionPane.showOptionDialog(null, "Para realizar o backup/restauração do sistema você deve ter o serviço MySQL instalado. Você deseja realizar um backup do sistema?", "Backup do Sistema", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options2, options2[0]);
//        if (j == JOptionPane.YES_OPTION) {
//            JOptionPane.showMessageDialog(null, "Informe o local onde será salvo o backup.", "Backup do Sistema", JOptionPane.INFORMATION_MESSAGE);
//            String localArquivo = "";
//            JFileChooser arquivo = new JFileChooser();
//            arquivo.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
//            if (arquivo.showOpenDialog(arquivo) == JFileChooser.APPROVE_OPTION) {
//                localArquivo = arquivo.getSelectedFile().getPath();
//            }
//            String path = "";
//            path = localArquivo.replace("\\", "/");
//            path = path.replace("/", "\\");
//            if (!path.equals("")) {
//                JOptionPane.showMessageDialog(null, "Não feche o programa, esta operação pode levar alguns minutos.", "Realizando Backup do Sistema", JOptionPane.INFORMATION_MESSAGE);
//                Backup backup = new Backup("mysqldump --host " + JanelaLogin.getServidor() + " -u " + JanelaLogin.getUsuarioBanco() + " -p" + JanelaLogin.getSenha() + " " + JanelaLogin.getBancoDados() + " -r C:\\backUpTaldi.sql", path);
//                backup.start();
//            }
//        }
//    } catch (Exception e) {
//        MensagemException.showMensageException(e, "Backup do Sistema");
//    }
}//GEN-LAST:event_jMenuItem15ActionPerformed

private void jMenuItem37ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem37ActionPerformed
//    try {
//        Object[] options2 = {"Sim", "Não"};
//        int j = JOptionPane.showOptionDialog(null, "Para realizar o backup/restauração do sistema você deve ter o serviço MySQL instalado. Você deseja realizar a restauração do sistema?", "Backup do Sistema", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options2, options2[0]);
//        if (j == JOptionPane.YES_OPTION) {
//            j = JOptionPane.showOptionDialog(null, "Atenção esta operação irá reconstruir todas as informações do sistema. Você deseja continuar", "Backup do Sistema", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options2, options2[0]);
//            if (j == JOptionPane.YES_OPTION) {
//                File file;
//                JFileChooser chooser = new JFileChooser();
//                FileFilter filtro = new FileFilter() {
//
//                    @Override
//                    public boolean accept(File f) {
//                        return f.getName().toLowerCase().endsWith(".sql")
//                                || f.isDirectory();
//                    }
//
//                    @Override
//                    public String getDescription() {
//                        return "Arquivos de Backup \".sql\"";
//                    }
//                };
//                chooser.setAcceptAllFileFilterUsed(false);
//                chooser.setFileFilter(filtro);
//                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
//                chooser.setMultiSelectionEnabled(false);
//
//                if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
//                    file = chooser.getSelectedFile();
//                    if (file.exists()) {
//                        String path = file.getAbsolutePath();
//                        path = path.replace("\\", "/");
//                        path = path.replace("/", "\\");
//                        String[] executeCmd = new String[]{"mysql", JanelaLogin.getBancoDados(), "--host=" + JanelaLogin.getServidor(), "--usuario=" + JanelaLogin.getUsuarioBanco(), "--password=" + JanelaLogin.getSenha(), "-e", " source " + path};
//                        new Restore(executeCmd);
//                    }
//                }
//            }
//        }
//    } catch (Exception e) {
//        MensagemException.showMensageException(e, "Restore do Sistema");
//    }
}//GEN-LAST:event_jMenuItem37ActionPerformed

private void jMenuItem38ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem38ActionPerformed
//    if (analisadorFaturas != null) {
//        analisadorFaturas.dispose();
//        analisadorFaturas = null;
//    }
//    analisadorFaturas = new Dialog_AnalisadorFatura(this, false);
//    analisadorFaturas.setLocationRelativeTo(null);
//    analisadorFaturas.setIconImage(this.getIcon());
//    analisadorFaturas.setVisible(true);
}//GEN-LAST:event_jMenuItem38ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    public static javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel5;
    public static javax.swing.JLabel jLabel55;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenu jMenu8;
    private javax.swing.JMenu jMenu9;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem10;
    private javax.swing.JMenuItem jMenuItem14;
    private javax.swing.JMenuItem jMenuItem15;
    private javax.swing.JMenuItem jMenuItem20;
    private javax.swing.JMenuItem jMenuItem29;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem34;
    private javax.swing.JMenuItem jMenuItem37;
    private javax.swing.JMenuItem jMenuItem38;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel20;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel25;
    private javax.swing.JPanel jPanel27;
    private javax.swing.JPanel jPanel28;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables
}
